package com.qd.qx.ui.module4;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qd.chatui.util.MyUtils;
import com.qd.common.base.BaseFragment;
import com.qd.common.commonutils.ImageLoaderUtils;
import com.qd.qx.R;
import com.qd.qx.bean.UserData;
import com.qd.qx.ui.main.activity.PhotosDetailActivity;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Code is far away from bug with the animal protecting
 * Author：ys on 2018/7/13
 * Function：我的模块
 */
public class MyFragment extends BaseFragment {


    @BindView(R.id.ivHeader)
    ImageView ivHeader;
    @BindView(R.id.tvName)
    TextView tvName;
    @BindView(R.id.tvRefcode)
    TextView tvRefcode;
    @BindView(R.id.tvDp)
    TextView tvDp;
    @BindView(R.id.rlMeinfo)
    RelativeLayout rlMeinfo;
    @BindView(R.id.rlShenpi)
    RelativeLayout rlShenpi;
    @BindView(R.id.rlGzq)
    RelativeLayout rlGzq;
    @BindView(R.id.rlQianjin)
    RelativeLayout rlQianjin;
    @BindView(R.id.rlShoucang)
    RelativeLayout rlShoucang;
    @BindView(R.id.rlTuchao)
    RelativeLayout rlTuchao;
    @BindView(R.id.rlShezhi)
    RelativeLayout rlShezhi;

    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_my_layout;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        if (TextUtils.isEmpty(UserData.getInstance().getHeaderImg())) {
            if (TextUtils.isEmpty(UserData.getInstance().getRealName())) {
                MyUtils.addNameToImageView(getActivity(), ivHeader, "未知");
            } else {
                MyUtils.addNameToImageView(getActivity(), ivHeader, MyUtils.splitLastStr(UserData.getInstance().getRealName()));
            }

        } else {
            ImageLoaderUtils.displayCircleRound(getActivity(), ivHeader, UserData.getInstance().getHeaderImg());
        }

        tvName.setText(UserData.getInstance().getRealName());
        tvRefcode.setText("(" + UserData.getInstance().getRefCode() + ")");
        tvDp.setText(UserData.getInstance().getOfficeName());
    }


    @OnClick({R.id.ivHeader, R.id.rlMeinfo, R.id.rlShenpi, R.id.rlGzq, R.id.rlQianjin, R.id.rlShoucang, R.id.rlTuchao, R.id.rlShezhi})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ivHeader:
                PhotosDetailActivity.startAction(getActivity(), UserData.getInstance().getHeaderImg());
                break;
            case R.id.rlMeinfo:
                MeInfoActivity.startAction(getActivity());
                break;
            case R.id.rlShenpi:
                break;
            case R.id.rlGzq:
                break;
            case R.id.rlQianjin:
                break;
            case R.id.rlShoucang:
                break;
            case R.id.rlTuchao:
                TuCaoActivity.startAction(getActivity());
                break;
            case R.id.rlShezhi:
                SettingActivity.startAction(getActivity());
                break;
        }
    }


}
